package com.vitabuybuy.tv.network

import com.library.common.net.NetUrl
import com.vitabuybuy.tv.dto.*
import rxhttp.IAwait
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

/**
 * 作者：SimGa
 * 日期：2020/12/3
 * 时间：17:04
 * 包名：com.vitabuybuy.tv.network
 */
object StoreRepository {

    fun getStoreDetail(storeId: Int?): IAwait<StroeDetailDto> {
        return RxHttp.postJson(NetUrl.api_stroe_detail)
            .add("id", storeId).toResponse()
    }

    fun getClassification(id: Int?): IAwait<MutableList<ClassificationDto>> {
        return RxHttp.postJson(NetUrl.api_stroe_category)
            .add("store", mapOf(Pair("id", id))).toResponse()
    }

    fun getBannerList(storeId: Int): IAwait<MutableList<BannerDto.SlideListBean>> {
        val params = mapOf(
            Pair(
                "pageable",
                mapOf(
                    Pair("page", 1),
                    Pair("size", 20),
                    Pair("desc", "id")
                )
            ),
            Pair("storeId", storeId)
        )
        return RxHttp.postJson(NetUrl.api_find_store_poster)
            .addAll(params).toResponse()
    }

    fun getLiveList(
        storeId: Int?,
        pageNumber: Int,
        pageSize: Int
    ): IAwait<MutableList<LiveListDto>> {
        val params = mapOf(
            Pair("store", mapOf(Pair("id", storeId))),
            Pair(
                "pageable",
                mapOf(
                    Pair("page", pageNumber),
                    Pair("size", pageSize)
                )
            )
        )
        return RxHttp.postJson(NetUrl.api_find_playback_live)
            .addAll(params).toResponse()
    }


    fun collectOrcancelStore(id: Int?, isFav: Boolean?): IAwait<String> {
        return if (isFav == false) {
            RxHttp.postJson(NetUrl.api_follow_store)
                .add("attention", mapOf(Pair("store", mapOf(Pair("id", id)))))
                .toResponse()
        } else {
            RxHttp.postJson(NetUrl.api_delete_follow_store)
                .add("store", mapOf(Pair("id", id)))
                .toResponse()
        }
    }

    fun collectOrcancelExecutor(id: Int?, isFav: Boolean): IAwait<String> {
        return if (!isFav) {
            RxHttp.postJson(NetUrl.api_follow_store)
                .add("attention", mapOf(Pair("executor", mapOf(Pair("id", id)))))
                .toResponse()
        } else {
            RxHttp.postJson(NetUrl.api_delete_follow_executor)
                .add("executor", mapOf(Pair("id", id)))
                .toResponse()
        }
    }
}